package com.bz.controller;

import com.bz.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {
    @GetMapping("findAll")
    public String findAll(Model model) {
        System.out.println("查询所有");
        model.addAttribute("name", "小城");
        model.addAttribute("username", "<a href=''>小程程</a>");
        model.addAttribute("user", new User("1","haha",new Date()));
        List<User> list = new ArrayList<>();
        list.add(new User("23","xiaohei",new Date()));
        list.add(new User("27","xiaohei",new Date()));
        list.add(new User("24","xiaohei",new Date()));
        model.addAttribute("list", list);
        return "index"; //沿用jsp的特性，跳转的逻辑名 classpath:/templates/逻辑名.html
    }

    @RequestMapping("/delete")
    @ResponseBody
    public String delete(String id){
        System.out.println("id+"+id);
        return id+"has deleted";
    }
}
